package com.csap.framework.integration.service.boot.autoconfigure;

import com.csap.framework.integration.RocketmqConfig;
import com.csap.framework.integration.boot.autoconfigure.RocketmqAutoConfiguration;
import com.csap.framework.integration.producer.RocketmqProducer;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author yangchengfu
 * @description 生产者服务端 配置
 * @dataTime 2020年-10月-12日 15:45:00
 **/
@Configuration
@Component("com.csap.framework.integration")
@ImportAutoConfiguration(RocketmqAutoConfiguration.class)
@ConditionalOnProperty(prefix = RocketmqConfig.prefix + ".producer", name = "enabled", havingValue = "true")
public class RocketmqServiceAutoConfiguration {

    @Bean(initMethod = "start", destroyMethod = "shutdown")
    public RocketmqProducer rocketmqProducer(RocketmqConfig rocketmqConfig) {
        RocketmqProducer producer = new RocketmqProducer();
        producer.setProperties(rocketmqConfig.getProducerProperties());
        return producer;
    }
}
